/*
 * SetArcWeightCommand.java
 *
 * Created on 11 maj 2007, 22:30
 */

package edu.uj.petri.commands;

import edu.uj.petri.model.NormalArc;
import java.util.ResourceBundle;

/**
 * Command setting weight of given arc from model.
 * @author Piotrek
 */
public class SetArcWeightCommand extends Command {
    
    private NormalArc arc;
    
    private int newWeight;
    
    private String description;
    
    private int oldWeight;
    
    private final static int NOT_SET=-1;
    
    /** Creates a new instance of SetArcWeightCommand */
    public SetArcWeightCommand(NormalArc arc, int weight) {
        this.arc = arc;
        this.newWeight = weight;
        this.description = ResourceBundle.getBundle("edu/uj/petri/messages").getString("ustawienie_wagi_krawedzi_na_")+Integer.toString(weight);
        oldWeight = NOT_SET;
    }

    public String toString() {
        return description;
    }

    void execute() {
        // it would be better to execute getMemento(), but we can be lazy here
        if (oldWeight == NOT_SET)
            oldWeight = arc.getWeight();
        arc.setWeight(newWeight);
    }

    void undo() {
        arc.setWeight(oldWeight);
    }

    boolean canBeCombined(Command c) {
        return false;
    }

    private static final long serialVersionUID = -7673588486104870785L;
    
}
